package com.handydata.antifraud.channel.outbound;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.retry.backoff.FixedBackOffPolicy;
import org.springframework.retry.policy.SimpleRetryPolicy;
import org.springframework.retry.support.RetryTemplate;
import org.springframework.stereotype.Component;

@Component
public class MyRetryTemplate extends RetryTemplate {

    @Value("${risk.shbank.sendback.retryCount}")
    private int sendAttemptsCount=1;
    @Value("${risk.shbank.sendback.retryPeriod}")
    private int sendAttemptsPeriod=2000;

    public MyRetryTemplate(){

        SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy();
        retryPolicy.setMaxAttempts(sendAttemptsCount);
        // 设置间隔策略
        FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy();
        backOffPolicy.setBackOffPeriod(sendAttemptsPeriod);

        this.setRetryPolicy(retryPolicy);
        this.setBackOffPolicy(backOffPolicy);

    }
}
